cached      = require('gulp-cached')
gulp        = require 'gulp'
paths       = require('../config.coffee').paths
remember    = require 'gulp-remember'
runSequence = require('run-sequence')

gulp.task 'watchReal', ['defaultReal'], -> # 测试机环境
    gulp.watch(paths.styles, ['styles'])
        .on 'change', (e) ->
            if e.type == 'deleted'
                delete cached.caches.stylesCache[e.path]
                remember.forget('stylesRem', e.path)

    gulp.watch(paths.scripts, ->
        runSequence('scripts')
    )
        .on 'change', (e) ->
            if e.type == 'deleted'
                delete cached.caches.coffeeCache[e.path]
                remember.forget('coffeeRem', e.path)
    gulp.watch paths.test, ->
        runSequence('test')
    gulp.watch paths.assets, ['assets']
    gulp.watch paths.index, ['index']
    gulp.watch paths.ionic_sass, ['ionic_sass']


gulp.task 'watchModal', ['defaultModal'], -> # 测试机环境
    gulp.watch(paths.styles, ['styles'])
    .on 'change', (e) ->
        if e.type == 'deleted'
            delete cached.caches.stylesCache[e.path]
            remember.forget('stylesRem', e.path)

    gulp.watch(paths.scripts, ->
        runSequence('scripts')
    )
    .on 'change', (e) ->
        if e.type == 'deleted'
            delete cached.caches.coffeeCache[e.path]
            remember.forget('coffeeRem', e.path)
    gulp.watch paths.test, ->
        runSequence('test')
    gulp.watch paths.assets, ['assets']
    gulp.watch paths.index_modal, ['index']
    gulp.watch paths.ionic_sass, ['ionic_sass']

gulp.task 'watch', ['default'], -> # mock环境
    gulp.watch(paths.styles, ['styles'])
        .on 'change', (e) ->
            if e.type == 'deleted'
                delete cached.caches.stylesCache[e.path]
                remember.forget('stylesRem', e.path)
    
    gulp.watch(paths.scripts, ->
        runSequence('scripts')
    )
        .on 'change', (e) ->
            if e.type == 'deleted'
                delete cached.caches.coffeeCache[e.path]
                remember.forget('coffeeRem', e.path)
    gulp.watch paths.test, ->
        runSequence('test')
    gulp.watch paths.assets, ['assets']
    gulp.watch paths.mocks, ['mocks']
    gulp.watch paths.mockIndex, ['mockIndex']
    gulp.watch paths.ionic_sass, ['ionic_sass']

